﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

namespace Workflow.Project
{
    public partial class SearchLog2 : System.Web.UI.Page
    {
        public SearchChoose objSearchChoose = new SearchChoose();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            string mold = txtMold.Text.Trim().ToUpper().ToString();
            string name = txtName.Text.Trim().ToString();
            string createDate1 = txtCreateDate1.Text.Length > 0 ? Convert.ToDateTime(txtCreateDate1.Text).ToString("yyyy-MM-dd") : "";
            string createDate2 = txtCreateDate2.Text.Length > 0 ? Convert.ToDateTime(txtCreateDate2.Text).ToString("yyyy-MM-dd") : "";
            string degree = "";
            for (int i = 0; i < cblDegree.Items.Count; i++)
            {
                if (cblDegree.Items[i].Selected)
                {
                    if (degree.Length == 0)
                    { degree = cblDegree.Items[i].Text; }
                    else { degree = degree + "," + cblDegree.Items[i].Text; }
                }
            }

            string department = "";
            for (int i = 0; i < cblDepartment.Items.Count; i++)
            {
                if (cblDepartment.Items[i].Selected)
                {
                    if (department.Length == 0)
                    { department = cblDepartment.Items[i].Text; }
                    else { department = department + "," + cblDepartment.Items[i].Text; }
                }
            }

            string labelType = "";
            for (int i = 0; i < cbllabelType.Items.Count; i++)
            {
                if (cbllabelType.Items[i].Selected)
                {
                    if (labelType.Length == 0)
                    { labelType = cbllabelType.Items[i].Text; }
                    else { labelType = labelType + "," + cbllabelType.Items[i].Text; }
                }
            }

            string url = "ShowLog.aspx?Mold=" + mold + "&Name=" + name + "&CreateDate1=" + createDate1;
            url += "&CreateDate2=" + createDate2 + "&Degree=" + degree + "&Department=" + department + "&LabelType=" + labelType;
            string msgForm = string.Format("<script>window.location.href = '{0}';</script>", url);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", msgForm);
        }

        protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            string msgForm = objSearchChoose.Choose(ddlSelect);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", msgForm);
        }
    }
}